﻿#region Imports
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
#endregion

namespace JounceSilverlightDemo.Converters
{
    /// <summary>
    /// Converts a boolean value into System.Windows.Visibility
    /// </summary>
    public class VisibilityConverter : IValueConverter
    {
        #region Methods
        /// <summary>
        /// requiredd converter format
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool source;
            try
            {
                source = (bool)value;
            }
            catch (Exception)
            {
                return Visibility.Collapsed;
            }

            if (parameter != null)
                if ((string)parameter == "-")
                    source = !source;

            switch ((bool)source)
            {
                case true:
                    return Visibility.Visible;
                case false:
                default:
                    return Visibility.Collapsed;
            }
        }
        /// <summary>
        /// ConvertBack to original value
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
        #endregion
    }
}
